
public class Threaddd {


    // multipart Threads 


    public static void main(String[] args) throws Exception {
        System.out.println("====================== synchronized -- lock -- unlock ====================");
        Thread ta = new AddCounter();
        Thread tr = new ReduceCouter();
        ta.start();
        tr.start();

        ta.join();
        tr.join();

        System.out.println(Counter.count);

    }
}


class Counter {
    public static final Object lock = new Object();
    public static int count ;
}


class  AddCounter extends Thread {
    public void run(){
       
       synchronized(Counter.lock){
            for(int i=0;i<=10000;i++){
                Counter.count ++;
            }
       }
    }
}


class ReduceCouter extends Thread {
    public void run(){
        synchronized(Counter.lock){
            for(int i=0;i<=10000;i++){
                Counter.count --;
            }
        }
    }
}